﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QuanLyGiaoDuc_Winform.ServiceXuLyThongTinKhoa;
using QuanLyGiaoDuc_Winform.ServiceXuLyThongTinLop;

namespace QuanLyGiaoDuc_Winform
{
    public partial class FormSapXepThoiKhoaBieu : Form
    {
        public FormSapXepThoiKhoaBieu()
        {
            InitializeComponent();
        }

        KHOA_getallResult[] list_khoa;
        ServiceXuLyThongTinKhoa.ServiceXuLyThongTinKhoaSoapClient proxy_Khoa = new ServiceXuLyThongTinKhoaSoapClient();
        ServiceXuLyThongTinLop.ServiceXuLyThongTinLopSoapClient proxy_lop = new ServiceXuLyThongTinLopSoapClient();
        
        public string[] thu = {"Thứ 2","Thứ 3","Thứ 4","Thứ 5","Thứ 6","Thứ 7"};
        public int[] tiet = {1,2,3,4,5,6,7,8,9,10,11,12};

        private void FormSapXepThoiKhoaBieu_Load(object sender, EventArgs e)
        {
        
            list_khoa = proxy_Khoa.layDanhSachKhoa();

            foreach (KHOA_getallResult a in list_khoa)
            {
                cbb_khoa.Items.Add(a.MAKHOA + ". " + a.TENKHOA);
            }
        }

        private void cbb_khoa_SelectedIndexChanged(object sender, EventArgs e)
        {
            dgv_SapXepTKB.Rows.Clear();
            LOP_getallwithMaKhoaResult[] ds_lop = proxy_lop.layDanhSachLopTheoMaKhoa(list_khoa[cbb_khoa.SelectedIndex].MAKHOA);


            for (int i = 0; i < ds_lop.Length; i++)
            {
                dgv_SapXepTKB.Rows.Add(i + 1, ds_lop[i].TENLOP, ds_lop[i].TENMONHOC);
                dgv_SapXepTKB.Rows[i].Tag = ds_lop[i];
            }

            ((DataGridViewComboBoxColumn)dgv_SapXepTKB.Columns[3]).DataSource = thu;
            ((DataGridViewComboBoxColumn)dgv_SapXepTKB.Columns[4]).DataSource = tiet;
            ((DataGridViewComboBoxColumn)dgv_SapXepTKB.Columns[5]).DataSource = tiet;
        }

        private void dgv_SapXepTKB_DataError(object sender, DataGridViewDataErrorEventArgs e)
        {

        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < dgv_SapXepTKB.Rows.Count; i++)
            {
                DataGridViewComboBoxCell ngay = new DataGridViewComboBoxCell();
                DataGridViewComboBoxCell tietbd = new DataGridViewComboBoxCell();
                DataGridViewComboBoxCell tietkt = new DataGridViewComboBoxCell();
                ngay = (DataGridViewComboBoxCell)dgv_SapXepTKB.Rows[i].Cells[3];
                tietbd = (DataGridViewComboBoxCell)dgv_SapXepTKB.Rows[i].Cells[4];
                tietkt = (DataGridViewComboBoxCell)dgv_SapXepTKB.Rows[i].Cells[5];

                try
                {
                    if (ngay.Value.ToString() != "" && tietbd.Value.ToString() != "" && tietkt.Value.ToString() != "")
                    {
                        LOP_getallwithMaKhoaResult lop_updated = new LOP_getallwithMaKhoaResult();
                        lop_updated = (LOP_getallwithMaKhoaResult)dgv_SapXepTKB.Rows[i].Tag;

                        proxy_lop.update_sapxepThoiKhoaBieu(lop_updated.MALOP, ngay.Value.ToString(), int.Parse(tietbd.Value.ToString()), int.Parse(tietkt.Value.ToString()));
                    }
                }
                catch
                {
                }
                MessageBox.Show("Lưu dữ liệu thành công");
            }

        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

    }
}
